package com.itheima.pro;



import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import java.util.Set;



public class Test7 extends Base64Demo{
    public static void main(String[] args) throws IOException {
//        properties文件中有两个键值对字符串分别为
//username=zhangsan
//password=123456
//请用properties的方法读取到Properties对象中。
//1.用Base64Demo提供的加密方法对value值进行加密，把加密后的数据覆盖到原properties文件中
//2.读取加密后的properties中的数据，把加密的密文进行解密 打印在控制台
        Properties pr = new Properties();
        FileReader fr=new FileReader("D:\\Develop\\workspace\\temp5\\day13\\src\\prop.properties");
        pr.load(fr);


        Set<Map.Entry<Object, Object>> entries = pr.entrySet();
        for (Map.Entry<Object, Object> entry : entries) {
            Object value = entry.getValue();
            String s = value.toString();
            System.out.println("value"+s);
            String ss = Base64Demo.encrypt(s);
            entry.setValue(ss);
            FileWriter fw=new FileWriter("D:\\Develop\\workspace\\temp5\\day13\\src\\prop.properties");
            pr.store(fw,null);
            fw.close();
        }
        System.out.println("加密"+pr);
        Set<Map.Entry<Object, Object>> entries1 = pr.entrySet();
        for (Map.Entry<Object, Object> entry2 : entries1) {
            Object value = entry2.getValue();
            String s = value.toString();
            String decode = Base64Demo.decode(s);
            entry2.setValue(decode);
        }
        System.out.println("解密"+pr);
        fr.close();


    }
}
